import { getCharts } from '@/api/home'

const state = () => {
  return {
    chartData: {}
  }
}

const mutations = {
  GET_DATA: (state, chartData) => {
    state.chartData = chartData
  }
}

const actions = {
  async getCharts({ commit }) {
    const {data} = await getCharts()
    if(data.code === 0){
      commit('GET_DATA', data.data)
    }else{
      return Promise.reject(new Error('获取失败 ！'))
    }
  }
}

const getters= {
  chartData(state){
    return state.chartData || {}
  },
}

export default {
  state,
  mutations,
  actions,
  getters
}
